package com.foreknow.demo9;

import java.io.*;

public class IODemo2 {
    public static void main(String[] args) {
        FileReader fr = null;
        BufferedReader br = null;
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            //创建一个节点流FileReader
            fr = new FileReader("IODemo1.java");
            //创建一个处理流用于对以上节点流功能的增强
            br = new BufferedReader(fr);
            //创建一个输出流FileWriter
            fw = new FileWriter("new_IODemo1.java");
            bw = new BufferedWriter(fw);
            //读取源文件中的一行数据
            String str = br.readLine();
            while (str != null) {
                //将读取到的str写到目标文件中
                bw.write(str);
                //换行
                bw.newLine();
                //读取下一行
                str = br.readLine();
            }
            br.close();
            bw.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
